package cn.njupt.countSort;

import cn.njupt.cmpSort.Sort;
//太消耗内存了并且不是稳定的排序
public class CountingSort extends Sort<Integer> {
    @Override
    public void sort() {
        //求最大值
        int max=array[0];
        for (int i = 1; i < array.length; i++) {
            max=Math.max(array[i],max);
        }
        //创建max+1长度的数组
        int[] help=new int[max+1];
        for (int i = 0; i < array.length; i++) {
            help[array[i]]++;
        }
        int index=0;
        for (int i = 0; i <help.length; i++) {
            if(help[i]==0)continue;
            while (help[i]-->0){
                array[index++]=i;
            }
        }

    }
}
